ops = ["5","2","C","D","+"]
var calPoints = function(operations) {
    let arr = []
    
    for(let i=0;i<operations.length;i++){
        if(operations[i]=='C'){
            arr.pop()
        }else if(operations[i]=='D'){
            arr.push(arr[arr.length-1]*2)
        }else if(operations[i]=='+'){
            arr.push(arr[arr.length-1]+arr[arr.length-2])
        }else{
            arr.push(Number(operations[i]))
        }
    }
    let ans = 0
    for(let item of arr){
        ans+=item
    }
    return ans
}
console.log(calPoints(ops));